package com.jsgt.greekfire.ui.mine.sermoncommunity

import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.fhx.core.base.BaseActivity
import com.jsgt.greekfire.R
import com.jsgt.greekfire.factory.CoinViewModelFactory
import com.jsgt.greekfire.ui.mine.sermoncommunity.adapter.SermonCommunityAdapter
import com.jsgt.greekfire.viewmodel.CoinViewModel
import kotlinx.android.synthetic.main.activity_sermon_community.*


class SermonCommunityActivity : BaseActivity() {

    private val coinViewModel: CoinViewModel by lazy {
        ViewModelProvider(
            this,
            CoinViewModelFactory()
        ).get(CoinViewModel::class.java)
    }

    val list: MutableList<MyCommunityItem> = ArrayList()

    private val communityAdapter: SermonCommunityAdapter by lazy { SermonCommunityAdapter() }

    override fun getLayoutId(): Int = R.layout.activity_sermon_community

    override fun needFitsSystemWindows(): Boolean {
        return false
    }

    override fun main() {

        title = getString(R.string.Sermon_community)

        coinViewModel.myCommunity()
        recyclerView.adapter = communityAdapter
        coinViewModel.myCommunityLiveData.observe(this, Observer {

            communityAdapter.refreshData(it.myCommunityItemList)

            Number_sermons.text = it.sermonNumb.toString()
            Number_communities.text = it.communityNumb.toString()
            showProgress(false)
        })


        coinViewModel.errorLiveData.observe(this, Observer {
            showProgress(false)
        })


    }

}